package eu.news.data.hibernate.pojo;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import eu.news.data.pojo.Sort;
import eu.news.data.pojo.Special;
import eu.news.kits.Backman;

/**
 * 专题
 * @author WZZ
 *
 */
@Entity
@Table(name="special")
public class HB_Special extends Special implements java.io.Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = -2424211300001533515L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	int id;
	
	/**
	 * 名称
	 */
	@Column(nullable=false,unique=true)
	String name;
	
	
	/**
	 * 主题
	 */
	String theme;
	
	/**
	 * 分类
	 */
	@OneToMany(cascade=CascadeType.ALL,mappedBy="special",fetch=FetchType.LAZY)
	Set<HB_Sort> sorts=new HashSet<HB_Sort>();

	public HB_Special(){};
	
	public HB_Special(String name) {
		super();
		this.name = name;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getTheme() {
		return theme;
	}

	public void setTheme(String theme) {
		this.theme = theme;
	}

	public Set<? extends Sort> getSorts() {
		return sorts;
	}

	@SuppressWarnings("unchecked")
	public void setSorts(Set<? extends Sort> sorts) {
		this.sorts = (Set<HB_Sort>) sorts;
	}
	
	public String getThemeName(){
		if(theme==null)
			return null;
		return Backman.getThemeByPath(theme).getName();
	}
}
